package com.edgar.hook;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.edgar.plugin.PluginManager;
import com.edgar.plugin.pm.IPluginInstallObserver;

import java.io.File;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PluginManager.getInstance().installPackage(new File(Environment.getExternalStorageDirectory(), "testpluginapk-debug.apk"),
                new IPluginInstallObserver() {
                    @Override
                    public void onInstalledSuccess(String packageName) {
                        Toast.makeText(MainActivity.this,"安装成功:"+packageName,Toast.LENGTH_LONG).show();
                        Intent intent = new Intent();
                        intent.setComponent(new ComponentName(packageName,"com.edgar.test.plugin.MainActivity"));
                        startActivity(intent);
                    }

                    @Override
                    public void onInstallError(int errorCode,String message) {
                        Toast.makeText(MainActivity.this,"安装失败,错误码"+errorCode,Toast.LENGTH_LONG).show();
                    }
                });
    }
}
